package com.onlyphoto.onlymall.mvp.model

import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.base.BaseModel
import com.onlyphoto.onlymall.base.BaseObserver
import com.onlyphoto.onlymall.bean.request.GoodsCondition
import com.onlyphoto.onlymall.bean.response.GoodsBean
import com.onlyphoto.onlymall.bean.response.Rotation
import com.onlyphoto.onlymall.bean.response.SingleActivityBean
import com.onlyphoto.onlymall.utils.ConfigUtil
import com.onlyphoto.onlymall.utils.RxTransformer


class MHomePageImpl : BaseModel() {

    var url = ""

    fun requestRotation(baseObserver: BaseObserver<ArrayList<Rotation>>) {
        url = ConfigUtil.instance.getUrl(Urls.ROTATION)
        apiService().rotation(url, 1)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun requestSingleActivity(use_range: Int, range_cat1_id: Int, baseObserver: BaseObserver<SingleActivityBean>) {
        url = ConfigUtil.instance.getUrl(Urls.ACTIVITY_SINGLE)
        apiService().singleActivity(url, use_range, range_cat1_id)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun requestGoods(condition: GoodsCondition, baseObserver: BaseObserver<ArrayList<GoodsBean>>) {
        url = ConfigUtil.instance.getUrl(Urls.GOODS_LIST)
        apiService().goods(url, condition.toMap())
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }
}
